<?php
include DIR_WS_CLASSES . 'kreditor_lang.php'; // xxx
require_once DIR_WS_CLASSES . 'kreditor.php';
global $kred_sek, $kred_nok, $kred_dkk, $kred_eur, $KRED_ISO3166_FI, $KRED_ISO3166_SE, $KRED_ISO3166_DK, $KRED_ISO3166_NO, $KRED_ISO3166_DE;
// Get the country specific settings based on currency

switch(strtolower($currency))
{
case 'sek':
$pclass = MODULE_PAYMENT_PCKREDITOR_PCLASS_DEFAULT;
$curr = $KRED_SEK;
$lang_month = KREDITOR_LANG_INFO_SE_PAYMENTTEXT2_EACH;
$lang_from = KREDITOR_LANG_INFO_SE_PARTPAYMENT_FROM;
$country = "se";
$eid = MODULE_PAYMENT_PCKREDITOR_EID;
$enabled = MODULE_PAYMENT_PCKREDITOR_STATUS;
$cc = $KRED_ISO3166_SE;
break;

case 'nok':
$pclass = MODULE_PAYMENT_PCKREDITOR_NOR_PCLASS_DEFAULT;
$curr = $KRED_NOK;
$lang_month = KREDITOR_LANG_INFO_NO_PAYMENTTEXT2_EACH;
$lang_from = KREDITOR_LANG_INFO_NO_PARTPAYMENT_FROM;
$country = "no";
$eid = MODULE_PAYMENT_PCKREDITOR_NOR_EID;
$enabled = MODULE_PAYMENT_PCKREDITOR_NOR_STATUS;
$cc = $KRED_ISO3166_NO;
break;

case 'dkk':
$pclass = MODULE_PAYMENT_PCKREDITOR_DEN_PCLASS_DEFAULT;
$curr = $KRED_DKK;
$lang_month = KREDITOR_LANG_INFO_DK_PAYMENTTEXT2_EACH;
$lang_from = KREDITOR_LANG_INFO_DK_PARTPAYMENT_FROM;
$country = "dk";
$eid = MODULE_PAYMENT_PCKREDITOR_DEN_EID;
$enabled = MODULE_PAYMENT_PCKREDITOR_DEN_STATUS;
$cc = $KRED_ISO3166_DK;
break;

case 'eur':
$hasgerman = false;
if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) { 

	$langarr=explode(",",$_SERVER["HTTP_ACCEPT_LANGUAGE"]);

	foreach ($langarr as $lang) {
		$langcode=substr($lang,0,2);
		
		if(strtolower($langcode) == "de") {
			$hasgerman = true;
			break;
		}
	}
} 

if($_SESSION["language"] == "german" || $hasgerman) {
$pclass = MODULE_PAYMENT_PCKREDITOR_DE_PCLASS_DEFAULT;
$curr = $KRED_EUR;
$lang_month = KREDITOR_LANG_INFO_DE_PAYMENTTEXT2_EACH;
$lang_from = KREDITOR_LANG_INFO_DE_PARTPAYMENT_FROM;
$country = "de";
$eid = MODULE_PAYMENT_PCKREDITOR_DE_EID;
$enabled = MODULE_PAYMENT_PCKREDITOR_DE_STATUS;
$fee = 195;
$rate = 1495;
$cc = $KRED_ISO3166_DE;
} else { 
$pclass = MODULE_PAYMENT_PCKREDITOR_FIN_PCLASS_DEFAULT;
$curr = $KRED_EUR;
$lang_month = KREDITOR_LANG_INFO_FI_PAYMENTTEXT2_EACH;
$lang_from = KREDITOR_LANG_INFO_FI_PARTPAYMENT_FROM;
$country = "fi";
$eid = MODULE_PAYMENT_PCKREDITOR_FIN_EID;
$enabled = MODULE_PAYMENT_PCKREDITOR_FIN_STATUS;
$fee = 395;
$rate = 2200;
$cc = $KRED_ISO3166_FI;
}
break;
}


    if ($new_price = tep_get_products_special_price($product_info['products_id'])) {
      $products_price = $currencies->calculate_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id']));
    } else {
      $products_price = $currencies->calculate_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']));
    }

// xxx Check to see that both the pclass for konto exists and that the
// latest pclass version is available
if(is_numeric($pclass) && $enabled == 'True')
{
switch(strtolower($currency))
{
case 'sek':
monthly_cost($products_price*100, 1950, 24, 2900, 1, $cc, $result);
break;

case 'nok':
monthly_cost($products_price*100, 2200, 24, 4500, 1, $cc, $result);
break;

case 'dkk':
monthly_cost($products_price*100, 2200, 24, 3900, 1, $cc, $result);
break;

case 'eur':
monthly_cost($products_price*100, $rate, 24, $fee, 1, $cc, $result);
break;


}
?>
<tr style="text-align: right;">
			<td class="smallText klarna_pp_td" valign="top" colspan="2"><strong> <?php echo $lang_from . " <span style=\"color: red;\" class=\"klarna_pp_span\">" . $currencies->format($result/100) . $lang_month . '</span>'?><strong>
			</td>
			</tr>
			<tr style="text-align: right;">
			<td class="smallText" valign="top" colspan="2">
			<script type="text/javascript" src="http://integration.klarna.com/js/klarnapart.js"></script>
<script>
addKlarnaPartPaymentEvent(function() { InitKlarnaPartPaymentElements('klarna_partpayment', '<?php echo $eid ?>', '<?php echo $country ?>'); });
</script>
	<a href="#" id="klarna_partpayment" onclick="ShowKlarnaPartPaymentPopup();return false;"></a>
			</td>
</tr>
<?php
}
?>
